//
//  WaitJPieces.m
//
//  Created by 春程 王 on 16/8/3
//  Copyright (c) 2016 __MyCompanyName__. All rights reserved.
//

#import "WaitJPieces.h"


NSString *const kWaitJPiecesNameSender = @"nameSender";
NSString *const kWaitJPiecesOrderId = @"orderId";
NSString *const kWaitJPiecesPhoneSender = @"phoneSender";
NSString *const kWaitJPiecesId = @"id";
NSString *const kWaitJPiecesTimeAdd = @"timeAdd";
NSString *const kWaitJPiecesAddressSender = @"addressSender";
NSString *const kWaitJPiecesAreaIdSender = @"area_id_sender";


@interface WaitJPieces ()

- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;

@end

@implementation WaitJPieces

@synthesize nameSender = _nameSender;
@synthesize orderId = _orderId;
@synthesize phoneSender = _phoneSender;
@synthesize jPiecesIdentifier = _jPiecesIdentifier;
@synthesize timeAdd = _timeAdd;
@synthesize addressSender = _addressSender;
@synthesize areaIdSender = _areaIdSender;


+ (instancetype)modelObjectWithDictionary:(NSDictionary *)dict
{
    return [[self alloc] initWithDictionary:dict];
}

- (instancetype)initWithDictionary:(NSDictionary *)dict
{
    self = [super init];
    
    // This check serves to make sure that a non-NSDictionary object
    // passed into the model class doesn't break the parsing.
    if(self && [dict isKindOfClass:[NSDictionary class]]) {
            self.nameSender = [self objectOrNilForKey:kWaitJPiecesNameSender fromDictionary:dict];
            self.orderId = [self objectOrNilForKey:kWaitJPiecesOrderId fromDictionary:dict];
            self.phoneSender = [self objectOrNilForKey:kWaitJPiecesPhoneSender fromDictionary:dict];
            self.jPiecesIdentifier = [self objectOrNilForKey:kWaitJPiecesId fromDictionary:dict];
            self.timeAdd = [self objectOrNilForKey:kWaitJPiecesTimeAdd fromDictionary:dict];
            self.addressSender = [self objectOrNilForKey:kWaitJPiecesAddressSender fromDictionary:dict];
            self.areaIdSender = [self objectOrNilForKey:kWaitJPiecesAreaIdSender fromDictionary:dict];

    }
    
    return self;
    
}

- (NSDictionary *)dictionaryRepresentation
{
    NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
    [mutableDict setValue:self.nameSender forKey:kWaitJPiecesNameSender];
    [mutableDict setValue:self.orderId forKey:kWaitJPiecesOrderId];
    [mutableDict setValue:self.phoneSender forKey:kWaitJPiecesPhoneSender];
    [mutableDict setValue:self.jPiecesIdentifier forKey:kWaitJPiecesId];
    [mutableDict setValue:self.timeAdd forKey:kWaitJPiecesTimeAdd];
    [mutableDict setValue:self.addressSender forKey:kWaitJPiecesAddressSender];
    [mutableDict setValue:self.areaIdSender forKey:kWaitJPiecesAreaIdSender];

    return [NSDictionary dictionaryWithDictionary:mutableDict];
}

- (NSString *)description 
{
    return [NSString stringWithFormat:@"%@", [self dictionaryRepresentation]];
}

#pragma mark - Helper Method
- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict
{
    id object = [dict objectForKey:aKey];
    return [object isEqual:[NSNull null]] ? nil : object;
}


#pragma mark - NSCoding Methods

- (id)initWithCoder:(NSCoder *)aDecoder
{
    self = [super init];

    self.nameSender = [aDecoder decodeObjectForKey:kWaitJPiecesNameSender];
    self.orderId = [aDecoder decodeObjectForKey:kWaitJPiecesOrderId];
    self.phoneSender = [aDecoder decodeObjectForKey:kWaitJPiecesPhoneSender];
    self.jPiecesIdentifier = [aDecoder decodeObjectForKey:kWaitJPiecesId];
    self.timeAdd = [aDecoder decodeObjectForKey:kWaitJPiecesTimeAdd];
    self.addressSender = [aDecoder decodeObjectForKey:kWaitJPiecesAddressSender];
    self.areaIdSender = [aDecoder decodeObjectForKey:kWaitJPiecesAreaIdSender];
    return self;
}

- (void)encodeWithCoder:(NSCoder *)aCoder
{

    [aCoder encodeObject:_nameSender forKey:kWaitJPiecesNameSender];
    [aCoder encodeObject:_orderId forKey:kWaitJPiecesOrderId];
    [aCoder encodeObject:_phoneSender forKey:kWaitJPiecesPhoneSender];
    [aCoder encodeObject:_jPiecesIdentifier forKey:kWaitJPiecesId];
    [aCoder encodeObject:_timeAdd forKey:kWaitJPiecesTimeAdd];
    [aCoder encodeObject:_addressSender forKey:kWaitJPiecesAddressSender];
    [aCoder encodeObject:_areaIdSender forKey:kWaitJPiecesAreaIdSender];
}

- (id)copyWithZone:(NSZone *)zone
{
    WaitJPieces *copy = [[WaitJPieces alloc] init];
    
    if (copy) {

        copy.nameSender = [self.nameSender copyWithZone:zone];
        copy.orderId = [self.orderId copyWithZone:zone];
        copy.phoneSender = [self.phoneSender copyWithZone:zone];
        copy.jPiecesIdentifier = [self.jPiecesIdentifier copyWithZone:zone];
        copy.timeAdd = [self.timeAdd copyWithZone:zone];
        copy.addressSender = [self.addressSender copyWithZone:zone];
        copy.areaIdSender = [self.areaIdSender copyWithZone:zone];
    }
    
    return copy;
}


@end
